package com.qeng.aiwanba.util;

import android.content.Context;
import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lixy on 2017/9/22.
 */

public class JsParamsUtil {
    private static Map<String,Object> paramsMap = new HashMap<>();

    public static void saveTempParam(String key,String value){
        paramsMap.put(key,value);
    }

    public static Map<String,Object> getTempParams(){
        return paramsMap;
    }

    public static Object getTempByKey(String key){
        if(!paramsMap.containsKey(key)){
            return null;
        }
        return paramsMap.get(key);
    }

    public static void removeTempParam(String key){
        if(paramsMap.containsKey(key)){
            paramsMap.remove(key);
        }
    }

    public static void removeAllTemp(){
        paramsMap.clear();
    }

    public static void saveSpParam(Context context,String key, String value){
        SharedPreferencesUtil.setJsValue(context,key,value);
    }

    public static Map<String,?> getSpParams(Context context){
        Log.e("tag","sp count:"+SharedPreferencesUtil.getAllJsValue(context));
        return SharedPreferencesUtil.getAllJsValue(context);
    }

    public static Object getSpParamsByKey(Context context,String key,String defaultValue){
        return Util.dealString((String)SharedPreferencesUtil.getJsValue(context,key,defaultValue));
    }

    public static void removeSpParam(Context context,String key){
        SharedPreferencesUtil.removeJsValue(context,key);
    }

    public static void removeAllSpParams(Context context){
        SharedPreferencesUtil.removeJsAllValue(context);
    }

    public static List<String> getTempAllKeys(Context context){
        return new ArrayList<>(paramsMap.keySet());
    }

    public static List<String> getSpAllKeys(Context context){
        return new ArrayList<>(getSpParams(context).keySet());
    }
}
